#!/usr/bin/env python
"""
# -*- coding: utf-8 -*-
# @Time    : 2020/10/8 10:28
# @Author  : AshJo
# @Desc    : 队列
# @Filename: queue_demo.py
# @Version : v1.0
"""

from multiprocessing import Process, Queue
import random
import time


def consumer(q, name):
    while True:
        food = q.get()
        if food:
            print(f'{name}吃了{food}')
        else:
            break


def producer(q, name, food):
    for i in range(10):
        foodi = f'{food}{i}'
        print(f'{name}生产了{foodi}')
        time.sleep(random.random())
        q.put(foodi)


if __name__ == '__main__':
    q = Queue()
    p1 = Process(target=producer, args=(q, '阿里巴巴', '香蕉'))
    c1 = Process(target=consumer, args=(q, '大壮'))
    p1.start()
    c1.start()
    p1.join()
    c1.join()
    q.put(None)
